package org.jeecg.modules.system.service.impl;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.system.entity.AppDeviceFreeze;
import org.jeecg.modules.system.mapper.AppDeviceFreezeMapper;
import org.jeecg.modules.system.service.IAppDeviceFreezeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 异常设备管理
 * @Author: jeecg-boot
 * @Date: 2025-05-31
 * @Version: V1.0
 */
@Service
public class AppDeviceFreezeServiceImpl extends ServiceImpl<AppDeviceFreezeMapper, AppDeviceFreeze> implements IAppDeviceFreezeService {

    //封装了redis操作各种方法
    @Autowired
    private RedisUtil redisUtil;


    @Override
    public List<AppDeviceFreeze> getList() {
        Object o = redisUtil.get(key());
        if (ObjectUtils.isNotNull(o)) {
            List<AppDeviceFreeze> list = (List<AppDeviceFreeze>) o;
            return list;
        } else {
            List<AppDeviceFreeze> list = this.list();
            redisUtil.set(key(), list);
            return list;
        }
    }

    public void cleanRedis() {
        redisUtil.del(key());
    }


    private String key() {
        return "app:device:freeze";
    }
}
